<?php
/**
 * Created by PhpStorm.
 * User: Zhanghaiqiang
 * Date: 2019-12-28
 * Time: 09:07
 */

namespace App\Http\Controllers\Api;

use App\Core\Endpoints\CandyBase\UploadCandyStoryStrImage;
use App\Core\Endpoints\CandyBase\UploadCandyStrImage;
use App\Core\Endpoints\CandyContent\UploadImages;
use App\Core\Endpoints\CandyLab\IndexLab;
use App\Core\Endpoints\CandyStory\CreateStory;
use App\Core\Endpoints\CandyStory\IndexStory;
use Endpoints\CandyBase\CandyConfig;
use Endpoints\CandyCalendar\IndexCalendar;
use Endpoints\CandyContent\CreateContent;
use Endpoints\CandyTech\IndexTech;
use Illuminate\Http\Request;
use Laravelladder\Core\Controllers\BaseController;
use Models\Candy\Content;

class CandyController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     * @throws \Laravelladder\Core\Exceptions\Endpoints\ArgumentRequiredException
     * @throws \Laravelladder\Core\Exceptions\Validations\ValidationException
     */
    public function imageIndex(Request $request){
        return IndexCalendar::getInstance()
            ->setArguments([
                IndexCalendar::ARGUMENT_PAGE    => $request->input(IndexCalendar::ARGUMENT_PAGE),
                IndexCalendar::ARGUMENT_P_LIMIT => $request->input(IndexCalendar::ARGUMENT_P_LIMIT),
                IndexCalendar::ARGUMENT_MEDIA_TYPE => Content::FILE_TYPE_VALUE_IMAGE,
                IndexCalendar::ARGUMENT_DATE_BEFORE => $request->input(IndexCalendar::ARGUMENT_DATE_BEFORE),
            ])
            ->fire();
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     * @throws \Laravelladder\Core\Exceptions\Endpoints\ArgumentRequiredException
     * @throws \Laravelladder\Core\Exceptions\Validations\ValidationException
     */
    public function videoIndex(Request $request){
        return IndexCalendar::getInstance()
            ->setArguments([
                IndexCalendar::ARGUMENT_PAGE    => $request->input(IndexCalendar::ARGUMENT_PAGE),
                IndexCalendar::ARGUMENT_P_LIMIT => $request->input(IndexCalendar::ARGUMENT_P_LIMIT),
                IndexCalendar::ARGUMENT_MEDIA_TYPE => Content::FILE_TYPE_VALUE_VIDEO,
            ])
            ->fire();
    }

    /**
     * @param Request $request
     * @return mixed|string|null
     * @throws \Laravelladder\Core\Exceptions\Endpoints\ArgumentRequiredException
     * @throws \Laravelladder\Core\Exceptions\Validations\ValidationException
     */
    public function contentCreate(Request $request){
        return CreateContent::getInstance()
            ->setArguments([
                CreateContent::ARGUMENT_FILES       => $request->input(CreateContent::ARGUMENT_FILES),
                CreateContent::ARGUMENT_SORT        => $request->input(CreateContent::ARGUMENT_SORT),
                CreateContent::ARGUMENT_SAVE_DATE   => $request->input(CreateContent::ARGUMENT_SAVE_DATE),
                CreateContent::ARGUMENT_TITLE       => $request->input(CreateContent::ARGUMENT_TITLE),
                CreateContent::ARGUMENT_DESCRIPTION => $request->input(CreateContent::ARGUMENT_DESCRIPTION),
                CreateContent::ARGUMENT_IS_PRIVATE  => $request->input(CreateContent::ARGUMENT_IS_PRIVATE),
                CreateContent::ARGUMENT_INTRO       => $request->input(CreateContent::ARGUMENT_INTRO),
            ])->fire();
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     * @throws \Laravelladder\Core\Exceptions\Endpoints\ArgumentRequiredException
     * @throws \Laravelladder\Core\Exceptions\Validations\ValidationException
     */
    public function techIndex(Request $request){
        return IndexTech::getInstance()
            ->setArguments([
                IndexTech::ARGUMENT_PAGE    => $request->input(IndexTech::ARGUMENT_PAGE),
                IndexTech::ARGUMENT_P_LIMIT => $request->input(IndexTech::ARGUMENT_P_LIMIT)
            ])
            ->fire();
    }

    /**
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function getConfig(){
        return CandyConfig::getInstance()->fire();
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     * @throws \Laravelladder\Core\Exceptions\Endpoints\ArgumentRequiredException
     * @throws \Laravelladder\Core\Exceptions\Validations\ValidationException
     */
    public function storyIndex(Request $request){
        return IndexStory::getInstance()
            ->setArguments([
                IndexStory::ARGUMENT_PAGE     => $request->input(IndexStory::ARGUMENT_PAGE),
                IndexStory::ARGUMENT_PER_PAGE => $request->input(IndexStory::ARGUMENT_PER_PAGE),
            ])
            ->fire();
    }

    /**
     * 上传base64到阿里云
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     * @throws \Laravelladder\Core\Exceptions\Endpoints\ArgumentRequiredException
     * @throws \Laravelladder\Core\Exceptions\Validations\ValidationException
     */
    public function imageUploadToOss(Request $request){
        return UploadCandyStoryStrImage::getInstance()
            ->setArguments([
                UploadCandyStoryStrImage::ARGUMENT_STR_IMAGE => $request->input(UploadCandyStoryStrImage::ARGUMENT_STR_IMAGE),
                UploadCandyStoryStrImage::ARGUMENT_DATE => $request->input(UploadCandyStoryStrImage::ARGUMENT_DATE),
            ])
            ->fire();
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     * @throws \Laravelladder\Core\Exceptions\Endpoints\ArgumentRequiredException
     * @throws \Laravelladder\Core\Exceptions\Validations\ValidationException
     */
    public function storyCreate(Request $request){
        return CreateStory::getInstance()
            ->setArguments([
                CreateStory::ARGUMENT_MEDIA_CONTENTS => $request->input(CreateStory::ARGUMENT_MEDIA_CONTENTS),
                CreateStory::ARGUMENT_TITLE => $request->input(CreateStory::ARGUMENT_TITLE),
                CreateStory::ARGUMENT_CONTENT => $request->input(CreateStory::ARGUMENT_CONTENT),
                CreateStory::ARGUMENT_DATE => $request->input(CreateStory::ARGUMENT_DATE),
                CreateStory::ARGUMENT_TYPE => $request->input(CreateStory::ARGUMENT_TYPE),
            ])
            ->fire();
    }

    /**
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
     */
    public function laboratoryIndex(){
        return IndexLab::getInstance()->fire();
    }

}